﻿<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />



    <link rel="stylesheet" href="../content/css/font.css">
    <link rel="stylesheet" href="../content/css/xadmin.css">
    <link rel="stylesheet" href="../content/plugin/bootstrap/css/bootstrap.min.css">
    <link rel='stylesheet' href='../content/plugin/bootstrap/css/style.css' />

    <script src="../content/js/jquery-1.10.2.min.js"></script>

    <script type="text/javascript" src="../content/js/xadmin.js"></script>
    <script type="text/javascript" src="../content/js/cookie.js"></script>
    <script src="../content/lib/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../content/plugin/FileUpload/css/jquery.fileupload.css" />
    <style>
        .active {
            color: green !important;
        }

        .mtable {
            border-collapse: collapse;
            margin: 0 auto;
            text-align: center;
        }

        .mtable td,
        table th {
            border: 1px solid #cad9ea;
            color: #666;
            height: 30px;
            text-align: center;
        }

        .mtable thead th {
            background-color: #CCE8EB;
            width: 100px;
        }

        .mtable tr:nth-child(odd) {
            background: #fff;
        }

        .mtable tr:nth-child(even) {
            background: #F5FAFA;
        }

        .choose {
            background-color: burlywood !important;
        }
    </style>



</head>

<body>
    <div id="app">
        <div class="x-nav">

            <span class="nav-header">
                <a href="">首页</a>>
                <a href="">发货管理</a>>

            </span>

        </div>
        <div class="x-body">
            <div class="layui-row">
                订单号：
                <input type="text" name="username" placeholder="" v-model="search.order_no" autocomplete="off"
                    style="height:30px;width: 150px;">
                编号：
                <input type="text" name="username" placeholder="" v-model="search.ordernum" autocomplete="off"
                    style="height:30px;width: 150px;">
                姓名 <input type="text" name="" placeholder="" v-model="search.truename" autocomplete="off"
                    style="height:30px;width: 150px;">
                物流单号 <input type="text" name="" placeholder="" v-model="search.express_no" autocomplete="off"
                    style="height:30px;width: 150px;">
                日期：
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="mydate" placeholder=" - ">



                </div>
                是否发货
                <select v-model="search.state" style="height:30px;width: 80px;">
                    <option value="">
                        请选择
                    </option>
                    <option v-for="item in statelist" :value='item.id'>
                        {{item.name}}
                    </option>
                </select>
                <button class="layui-btn" v-on:click="getdata"><i class="layui-icon">&#xe615;</i></button>


            </div>
            <div>
                用户名：
                <input type="text" name="" placeholder="" v-model="search.phone" autocomplete="off"
                    style="height:30px;width: 100px;">
                <button class="layui-btn" @click="downloadxls">导入模板</button>

                <button class="layui-btn" id="daoru">导入</button>

                <button class="layui-btn" @click="exportExcel">导出</button>
                <button class="layui-btn" @click="exportExcel1">导出宝贝</button>

                <button class="layui-btn" @click="exportimg">导出身份证</button>
            </div>

            <hr />

            <div class="table-responsive">
                <table id="tableExcel" class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th class="noExl">
                                ID</th>
                            <th> 订单号</th>
                            <th> 用户名</th>
                            <th> 头像</th>
                            <th>昵称</th>

                            <th> 编号</th>
                            <th> 备注</th>


                            <th> 收货人姓名</th>
                            <th> 收货人电话</th>
                            <th> 地址</th>
                            <th> 状态</th>
                            <th> 下单时间</th>
                            <th> 物流单号</th>
                            <th> 重量</th>
                            <th> 发货时间</th>
                            <th> 操作</th>


                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="uitem in arrayData">
                            <td class="noExl">{{uitem.id}}</td>
                            <td>
                                <a @click="setdata(uitem)" style="color:red"
                                    :class="{'active':uitem.content!=''&&uitem.content!=null&&uitem.content!='[]'}">{{uitem.order_no}}</a>
                            </td>
                            <td>{{uitem.phone}}</td>
                            <td>

                                <img :src="uitem.avatarurl" style="width: 50px;" />



                            </td>
                            <td>{{uitem.nickname}}</td>
                            <td>{{uitem.ordernum}}</td>
                            <td>{{uitem.descs}}</td>



                            <td>{{uitem.truename}}</td>
                            <td>{{uitem.addressphone}}</td>
                            <td>{{uitem.address}} {{uitem.datail}}</td>

                            <td>

                                <span v-if="uitem.state==0">待发货</span>
                                <span v-if="uitem.state==1">已发货</span>

                            </td>


                            <td>{{uitem.createtime}}</td>
                            <td>
                                {{uitem.express_no}}
                            </td>
                            <td>
                                {{uitem.weight}}
                            </td>
                            <td>{{uitem.express_time}}</td>

                            <td class="td-manage">

                                <a v-on:click="fahuo(uitem)" v-if="uitem.state==0" href="javascript:;">
                                    发货
                                </a>
                                <a v-on:click="edit(uitem)" href="javascript:;">
                                    修改
                                </a>
                                <a title="删除" v-on:click="vdel(uitem)" v-if="check()" href="javascript:;">
                                    删除
                                </a>


                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="page">
                <div>
                    <vue-nav :cur="search.page" :all="all" :allcount="allcount" :callback="callback"></vue-nav>
                </div>
            </div>

        </div>


        <div class="modal fade" id="addbox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">发货</h4>
                    </div>
                    <div class="modal-body">
                        <fieldset>

                            <div class="control-group">
                                <label for="input01" class="control-label">订单号</label>
                                <div class="controls">
                                    {{info.order_no}}
                                </div>
                            </div>


                            <div class="control-group">
                                <label for="input01" class="control-label">物流单号</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="info.express_no">
                                </div>
                            </div>
                            <div class="control-group">
                                <label for="input01" class="control-label">重量</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="info.weight">
                                </div>
                            </div>


                        </fieldset>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" v-on:click="insert()">确认</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <div class="modal fade" id="editbox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="myModalLabel">修改信息</h4>
                    </div>
                    <div class="modal-body">
                        <fieldset>


                            <div class="control-group">
                                <label for="input01" class="control-label">编号</label>
                                <div class="controls">
                                    <input placeholder="" type="text" class="form-control" v-model="editobj.ordernum">
                                </div>
                            </div>



                        </fieldset>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" v-on:click="update()">确认</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="setdatabox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
            aria-hidden="true">
            <div class="modal-dialog" style="width:80%">
                <div class="modal-content" id="myModal">
                    <div class="modal-header">

                        <h4 class="modal-title" id="myModalLabel">商品配置</h4>
                    </div>
                    <div class="modal-body">
                        <div>
                            物品编号：
                            <input type="text" v-model="searchgoods.code" placeholder="" autocomplete="off"
                                style="height:30px;width: 100px;">
                            物品名称：
                            <input type="text" v-model="searchgoods.name" placeholder="" autocomplete="off"
                                style="height:30px;width: 100px;">



                            <button class="layui-btn" @click="searchdatabykey()"><i
                                    class="layui-icon">&#xe615;</i></button>
                        </div>
                        <hr />

                        <form action="" v-on:submit.prevent="updatedata">
                            <fieldset>


                                <div style="height: 350px;overflow:scroll;">
                                    <table class="mtable">
                                        <thead>
                                            <tr>

                                                <th>序号</th>
                                                <th>操作</th>
                                                <th style="width: 120px;">商品编号</th>
                                                <th>物品名称</th>
                                                <th>日文名称</th>
                                                <th>型号规格</th>
                                                <th>重量</th>
                                                <th>数量</th>
                                                <th>价格</th>
                                                <th>扫码时间</th>

                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr v-for="(uitem,index)  in chooseitem" :key="index"
                                                v-bind:class="{ choose: uitem.choose }" @click="chooserow(uitem)">
                                                <td>
                                                    {{index+1}}
                                                </td>
                                                <td class="td-manage">
                                                    <a title="编辑" v-on:click="delitem(uitem)" href="javascript:;">
                                                        删除
                                                    </a>

                                                </td>
                                                <td>
                                                    <input type="text" v-model="uitem.code" />
                                                </td>
                                                <td>

                                                    <input type="text" v-model="uitem.name" />
                                                </td>
                                                <td>

                                                    <input type="text" v-model="uitem.name_japan" />
                                                </td>
                                                <td>

                                                    <input type="text" v-model="uitem.format" />

                                                </td>
                                                <td>

                                                    <input type="text" v-model="uitem.weight" />

                                                </td>

                                                <td>
                                                    <input type="number" v-model="uitem.num" style="width:50px;" />
                                                </td>
                                                <td>
                                                    <input type="number" v-model="uitem.xsprice" style="width:100px;" />
                                                </td>
                                                <td>

                                                    {{uitem.time}}


                                                </td>



                                            </tr>
                                        </tbody>


                                    </table>
                                </div>




                            </fieldset>
                            <div class="modal-footer">
                                <button type="button" @click="addnew" class="btn btn-primary">新增一行</button>

                                <button type="submit" class="btn btn-primary">确定</button>
                                <button type="button" class="btn" @click="closedialog">关闭</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>





        <input type="hidden" id="state" value="0" />


    </div>
    <link href="../content/plugin/sweetalert/sweetalert.css" rel="stylesheet">
    <script src="../content/plugin/sweetalert/sweetalert.min.js"></script>
    <script src="../content/plugin/bootstrap/js/bootstrap.min.js"></script>
    <script src="../content/js/vue2.js"></script>
    <script src="../content/js/vue-nav.js"></script>
    <script src="../content/js/config.js"></script>


    <script type="text/javascript" src="../content/js/moment.js"></script>
    <script>
        var timeScope;

        layui.use('laydate', function () {
            var laydate = layui.laydate;
            timeScope = laydate.render({
                elem: '#mydate'
                , range: true
                , ready: function (date) {
                    console.log("1", date); //得到初始的日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                }
            });

        });
        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#daoru'
                , url: '/upload/file' //改成您自己的上传接口
                , accept: 'file'
                , field: "imgFile"
                , before: function (obj) {

                }
                , done: function (res) {
                    //如果上传失败
                    console.log("res", res);
                    if (res.code == 200) {
                        $.post("/admin/order/importorder", { data: res.file, token: json.token }, function (data) {
                            if (data.status == 200) {
                                layer.msg("导入成功");
                                setTimeout(() => {
                                    window.location.reload();
                                }, 1000);
                            } else {
                                layer.msg(data.message);
                            }
                        })
                    } else {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    layer.msg("上传失败");
                }
            });
        });


        Array.prototype.remove = function (val) {
            var index = this.indexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        };
        var vm = new Vue({
            el: "#app",
            data: {
                all: 0,
                search: {
                    page: 1,
                    size: 10,
                    mid: localStorage.getItem("mid"),
                    ordernum: "",
                    order_no: "",
                    truename: "",
                    express_no: "",
                    phone: "",
                    state: ""

                },

                arrayData: [],
                allcount: 0,
                info: {

                },
                menulist: [],
                addobj: {
                    parentid: 0
                },
                editobj: {},
                datalist: [],
                statelist: [{ "id": 1, "name": "是" }, { "id": 0, "name": "否" }],
                wuliulist: [],
                editobj: {},
                chooseitem: [],
                sum: 0,
                state: "0",
                searchgoods: {}
            },
            components: {
                'vue-nav': Vnav
            },
            methods: {
                downloadxls() {
                    window.open("/admins/content/xls/订单导入模板.xls");
                },
                importdata() {

                },
                exportExcel() {
                    var ordernum = this.search.ordernum;
                    var order_no = this.search.order_no;
                    var truename = this.search.truename;
                    var express_no = this.search.express_no;
                    var phone = this.search.phone;
                    var state = this.search.state;

                    var stime = $("#mydate").val().split(" - ")[0];
                    var etime = $("#mydate").val().split(" - ")[1];

                    if (stime == undefined) {
                        stime = "";
                    }
                    if (etime == undefined) {
                        etime = "";
                    }

                    window.open("/admin/order/exportExcelorder?ordernum=" + ordernum + "&order_no=" + order_no + "&truename=" + truename + "&express_no=" + express_no + "&stime=" + stime + "&etime=" + etime + "&phone=" + phone + "&state=" + state);

                },
                exportExcel1() {
                    var ordernum = this.search.ordernum;
                    var order_no = this.search.order_no;
                    var truename = this.search.truename;
                    var express_no = this.search.express_no;
                    var phone = this.search.phone;
                    var state = this.search.state;

                    var stime = $("#mydate").val().split(" - ")[0];
                    var etime = $("#mydate").val().split(" - ")[1];

                    if (stime == undefined) {
                        stime = "";
                    }
                    if (etime == undefined) {
                        etime = "";
                    }

                    window.open("/admin/order/exportExcelorder1?ordernum=" + ordernum + "&order_no=" + order_no + "&truename=" + truename + "&express_no=" + express_no + "&stime=" + stime + "&etime=" + etime + "&phone=" + phone + "&state=" + state);

                },
                exportimg() {
                    var ordernum = this.search.ordernum;
                    var order_no = this.search.order_no;
                    var truename = this.search.truename;
                    var express_no = this.search.express_no;
                    var phone = this.search.phone;
                    var state = this.search.state;

                    var stime = $("#mydate").val().split(" - ")[0];
                    var etime = $("#mydate").val().split(" - ")[1];


                    if (stime == undefined) {
                        stime = "";
                    }
                    if (etime == undefined) {
                        etime = "";
                    }


                    window.open("/admin/order/exportimgorder?ordernum=" + ordernum + "&order_no=" + order_no + "&truename=" + truename + "&express_no=" + express_no + "&stime=" + stime + "&etime=" + etime + "&phone=" + phone + "&state=" + state);

                },
                check() {
                    if (localStorage.getItem("mid") == "0") {
                        return true;
                    } else {
                        return false;
                    }
                },
                searchdata: function () {
                    this.search.page = 1;
                    this.getdata();
                },


                getdata: function (_keycontent) {  //查询数据

                    var self = this;

                    var stime = $("#mydate").val().split(" - ")[0];
                    var etime = $("#mydate").val().split(" - ")[1];

                    if (stime == undefined) {
                        stime = "";
                    }
                    if (etime == undefined) {
                        etime = "";
                    }
                    this.search.stime = stime;
                    this.search.etime = etime;

                    $.post(apiurl + "/admin/order/orderlist", this.search, function (_result) {
                        console.log(_result);
                        self.arrayData = _result.data;
                        self.all = _result.allcount;
                        self.allcount = _result.count;
                    });

                },
                callback: function (data) {
                    var self = this;
                    this.search.page = data;

                    var stime = $("#mydate").val().split(" - ")[0];
                    var etime = $("#mydate").val().split(" - ")[1];

                    if (stime == undefined) {
                        stime = "";
                    }
                    if (etime == undefined) {
                        etime = "";
                    }
                    this.search.stime = stime;
                    this.search.etime = etime;

                    $.post(apiurl + "/admin/order/orderlist", this.search, function (_result) {
                        self.arrayData = _result.data;
                        self.all = _result.allcount;
                        self.allcount = _result.count;
                    });
                },
                chooserow(uitem) {
                    console.log("ss", uitem);
                    this.chooseitem.forEach(e => {
                        e.choose = false;
                    })
                    uitem.choose = true;
                },
                vdel: function (uitem) {
                    var self = this;
                    swal({
                        title: "确定要删除吗?",
                        text: "",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "是",
                        cancelButtonText: '否',
                        closeOnConfirm: false
                    }, function () {


                        $.ajax({
                            url: apiurl + '/admin/order/orders/del',
                            type: 'DELETE',
                            data: { "ids": uitem.id },
                            success: function (result) {
                                if (result.status == 200) {
                                    swal("系统提示", "已删除", "success");
                                    self.getdata("");
                                } else {
                                    swal("系统提示", "系统异常", "success");
                                }
                            }
                        });

                    });
                },
                edit: function (uitem) {
                    this.editobj = uitem;
                    $("#editbox").modal('show');
                },
                fahuo: function (uitem) {

                    this.info = uitem;

                    $("#addbox").modal('show');


                },
                wuliu: function (uitem) {
                    this.info = uitem;
                    $("#wuliubox").modal('show');

                },
                insert: function () {
                    var self = this;

                    if (this.info.express_no == null || this.info.express_no == "") {

                        layer.msg("请输入物流单号");
                        return;
                    }
                    if (this.info.weight == null || this.info.weight == "") {

                        layer.msg("请输入重量");
                        return;
                    }

                    $.post(apiurl + "/admin/order/fahuo2", this.info, function (_result) {
                        if (_result.status == 200) {
                            $("#addbox").modal('hide');
                            swal("success", "操作成功", "success");
                            self.getdata("");
                        } else {
                            swal("系统提示", data.message, "error");
                        }
                    });
                },
                update: function () {
                    var self = this;


                    $.post(apiurl + "/admin/order/orderedit", this.editobj, function (_result) {
                        if (_result.status == 200) {
                            $("#editbox").modal('hide');
                            swal("success", "操作成功", "success");
                            self.getdata("");
                        } else {
                            swal("系统提示", _result.message, "error");
                        }
                    });
                },
                init: function () {

                    var self = this;
                    $.post(apiurl + "/admin/config/load", {}, function (_result) {
                        console.log(_result);
                        var info = _result.data;
                        self.wuliulist = info.wuliulist.split("/n");

                    });
                },
                pingjia(uitem) {
                    var self = this;
                    $.post(apiurl + "/admin/order/comment", { id: uitem.id }, function (_result) {
                        console.log(_result);
                        var info = _result.data;
                        info.imglist = JSON.parse(info.imglist);
                        self.info = info;
                    });


                    $("#pingjiabox").modal('show');
                },
                setdata(uitem) {
                    // return;
                    $("#state").val("1");
                    this.addobj = uitem;

                    if (uitem.content != null && uitem.content != "") {
                        this.chooseitem = JSON.parse(uitem.content);
                    } else {
                        this.chooseitem = [];
                    }

                    $("#setdatabox").modal('show');
                },
                closedialog() {
                    $("#state").val("0");
                    $("#setdatabox").modal('hide');
                },
                searchdatabykey: function () {
                    var that = this;
                    // code = code.split(",")[1];
                    $.post(apiurl + "/admin/jxc/productgood/find", this.searchgoods, function (data) {
                        if (data.status == 200) {

                            for (var i = 0; i < that.chooseitem.length; i++) {
                                // console.log()
                                if (that.chooseitem[i].choose) {
                                    that.chooseitem[i].code = data.data.code;
                                    that.chooseitem[i].num = 1;
                                    that.chooseitem[i].name = data.data.name;
                                    that.chooseitem[i].name_japan = data.data.name_japan;
                                    that.chooseitem[i].format = data.data.format;
                                    that.chooseitem[i].weight = data.data.weight;
                                    that.chooseitem[i].xsprice = data.data.xsprice;
                                    that.chooseitem[i].time = moment().format("YYYY-MM-DD HH:mm:ss");

                                    that.$forceUpdate();
                                    break;
                                }
                            }



                        } else {
                            // uitem.num = "";
                            // uitem.name = "";
                            // uitem.name_japan = "";
                            // uitem.format = "";
                            // uitem.weight = "";
                            // uitem.xsprice = "";
                            // uitem.time = "";

                            // that.$forceUpdate();
                        }
                    });
                },
                getgoodsbycode: function (code) {
                    var that = this;
                    // code = code.split(",")[1];
                    $.post(apiurl + "/admin/jxc/productgood/find", { code: code }, function (data) {
                        if (data.status == 200) {
                            that.additem(data.data);
                        } else {
                            layer.msg("产品库不存在");
                            // var obj = {};
                            // obj.time = moment().format("YYYY-MM-DD HH:mm:ss");
                            // that.chooseitem.push(obj);
                        }

                    });
                },
                addnew() {
                    this.chooseitem.forEach(e => {
                        e.choose = false;
                    })

                    var obj = {};
                    obj.choose = true;
                    obj.time = moment().format("YYYY-MM-DD HH:mm:ss");

                    this.chooseitem.push(obj);
                },
                additem: function (uitem) {


                    uitem.time = moment().format("YYYY-MM-DD HH:mm:ss");

                    console.log("aa");
                    var b = false;
                    for (var i = 0; i < this.chooseitem.length; i++) {
                        if (this.chooseitem[i].id == uitem.id) {
                            this.chooseitem[i].num = this.chooseitem[i].num + 1;

                            b = true;
                            break;
                        }
                    }
                    if (b == false) {
                        uitem.num = 1;
                        uitem.sum = uitem.num * uitem.price;
                        this.chooseitem.push(uitem);
                    } else {

                    }
                    var sum = 0;
                    this.chooseitem.forEach(v => {
                        sum += v.price * v.num;
                    });
                    this.sum = sum;
                    console.log(this.chooseitem);
                    layer.msg("操作成功");
                    this.$forceUpdate();
                    // $("#goodsbox").modal('hide');

                },
                delitem: function (uitem) {
                    this.chooseitem.remove(uitem);
                    var sum = 0;
                    this.chooseitem.forEach(v => {
                        sum += v.price * v.num;
                    });
                    this.sum = sum;
                },
                updatedata: function () {
                    var self = this;

                    var num = 0;

                    // if (this.chooseitem.length == 0) {

                    //     layer.msg("请选择产品")
                    //     return;
                    // }
                    // for (var i = 0; i < this.chooseitem.length; i++) {
                    //     num = num + this.chooseitem[i].num;

                    // }
                    var gids = JSON.stringify(this.chooseitem);
                    this.addobj.content = gids;
                    $.post(apiurl + "/admin/order/updatedata", this.addobj, function (data) {
                        if (data.status == 200) {
                            $("#setdatabox").modal('hide');
                            swal("success", "提交成功", "success");
                            $("#state").val("0");
                            self.getdata();
                        } else {
                            swal("系统提示", data.message, "error");
                        }

                    });

                },

            },
            created: function () {  //初始化事件里边去调用查询方法

                this.init();

                this.search.order_status = GetRequest("state");
                this.getdata("");



            }
        });





        window.onload = function () {
            console.log("!!!!");
            var code = "";
            var lastTime, nextTime;
            var lastCode, nextCode;

            document.onkeypress = function (e) {

                nextCode = e.which;
                nextTime = new Date().getTime();

                if (lastCode != null && lastTime != null && nextTime - lastTime <= 30) {
                    code += String.fromCharCode(lastCode);
                } else if (lastCode != null && lastTime != null && nextTime - lastTime > 100) {
                    code = "";
                }

                lastCode = nextCode;
                lastTime = nextTime;
            }

            this.onkeypress = function (e) {

                console.log("e", e.which);
                if (e.which == 13) {
                    console.log("进来了", vm)
                    var state = $("#state").val();
                    console.log("state", state);
                    if (state == "1") {
                        vm.getgoodsbycode(code);
                    } else {
                        vm.getdata()
                    }




                }
            }
        }

    </script>
</body>

</html>